#pragma once
#include "log/channel.hpp"
#include "log/message.hpp"
#include "event/mutex.hpp"
using JHCPP::event::CMutex;
#include <string>
#include <ostream>

namespace JHCPP
{
	namespace log
	{
		class CConsoleChannel: public CChannel
		{
		public:
			CConsoleChannel();
			CConsoleChannel(std::ostream& str);

			void log(const CMessage& msg);

		protected:
			~CConsoleChannel();

		private:
			std::ostream& m_str;
			static CMutex m_mutex;
		};

		class CColorConsoleChannel: public CChannel
		{
		public:	
			CColorConsoleChannel();
			CColorConsoleChannel(std::ostream& str);

			void log(const CMessage& msg);

			void setProperty(const std::string& name, const std::string& value);
			std::string getProperty(const std::string& name) const;

		protected:	
			enum Color
			{
				CC_DEFAULT      = 0x0027,
				CC_BLACK        = 0x001e,
				CC_RED          = 0x001f,
				CC_GREEN        = 0x0020,
				CC_BROWN        = 0x0021,
				CC_BLUE         = 0x0022,
				CC_MAGENTA      = 0x0023,
				CC_CYAN         = 0x0024,
				CC_GRAY         = 0x0025,
				CC_DARKGRAY     = 0x011e,
				CC_LIGHTRED     = 0x011f,
				CC_LIGHTGREEN   = 0x0120,
				CC_YELLOW       = 0x0121,
				CC_LIGHTBLUE    = 0x0122,
				CC_LIGHTMAGENTA = 0x0123,
				CC_LIGHTCYAN    = 0x0124,
				CC_WHITE        = 0x0125
			};

			~CColorConsoleChannel();
			Color parseColor(const std::string& color) const;
			std::string formatColor(Color color) const;
			void initColors();

		private:
			std::ostream&	m_str;
			bool			m_enableColors;
			Color			m_colors[9];
			static CMutex	m_mutex;
			static const std::string CSI;
		};


	}//end of namespace log
}//end of namespace JHCPP
